<?php

function tariff_get_list()
{
	$sql = 'SELECT id, label, price
	        FROM Tariff';
	$data = sql_query($sql);
	return $data;
}


function tariff_get_by_id($id)
{
	$id = intval($id);
	$sql = 'SELECT id, label, price
	        FROM Tariff
	        WHERE id = '.$id.';';
	$data = sql_query($sql);
	return mysql_fetch_assoc($data);	        
}


function tariff_add($label, $price)
{
	$label = mysql_real_escape_string($label);
	$price = floatval($price);
	$sql = 'INSERT INTO Tariff (label, price)
	        VALUES ("'.$label.'", '.$price.');';
	sql_query($sql);
}


function tariff_update($id, $label, $price)
{
	$id = intval($id);
	$label = mysql_real_escape_string($label);
	$price = floatval($price);
	$sql = 'UPDATE Tariff
	        SET label = "'.$label.'",
	            price = '.$price.'
	        WHERE id = '.$id.';';
	sql_query($sql);
}


function tariff_delete($id)
{
	$id = intval($id);
	$sql = 'DELETE FROM Tariff
	        WHERE id = '.$id.';';
	sql_query($sql);
}


